# Commands
gas := as -arch i386
nasm := nasm
cc := gcc -arch i386
ld := ld -arch i386  # The MacOS linkder does not work!
objcopy := /Users/laigd/Workspace/binutils-2.24/binutils/objcopy
dd := dd

# Variables
target := nasm
# Usage: make target=gas
# '@' means make will not display the content of the command

all: boot_$(target).bin
	$(dd) if=/dev/zero of=boot.img bs=512 count=2880
	$(dd) if=boot_$(target).bin of=boot.img bs=512 count=1
	# skip=x: skip x blocks of input file
	# seek=x: seek x blocks of output file before copying
	$(dd) if=/dev/random of=boot.img skip=1 seek=1 bs=512 count=2879

boot_gas.bin: boot_gas.s
	$(gas) boot_gas.s -o boot_gas.o
	# $(ld) boot_gas.o -o boot_gas.elf -e c -Tboot_gas.ld
	$(objcopy) -R .pdr -R .comment -R.note -S -O binary boot_gas.o boot_gas.bin

boot_nasm.bin: boot_nasm.s
	$(nasm) boot_nasm.s -o boot_nasm.bin

clean:
	rm -rf boot.o boot.bin boot.elf
	rm -rf boot_gas.o boot_gas.bin boot_gas.elf
	rm -rf boot_nasm.o boot_nasm.bin boot_nasm.elf
